<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>借还明细报表</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form action="reportLend/dolist" method="post" name="searchForm" id="searchForm" role="form" class="form-horizontal">
            <div class="form-group">
                    <label class="col-sm-1 control-label">物资名称：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" id="materialsName" name="materialsName" value="${entity.materialsName}" placeholder="物资名称">
                    </div>
                    <label class="col-sm-1 control-label">单据号：</label>
                    <div class="col-md-4">
                		<input type="text" class="form-control" id="code" name="code" value="${entity.code}" placeholder="单据号">                           
                    </div>
            </div>
            
            <div class="form-group">
                    <label class="col-sm-1 control-label">来往单位：</label>
                    <div class="col-md-4">
                                <d:select name="orgName" clazz="selectpicker" id="orgName" list="${orgNames}" selected="${entity.orgName}"/>
                    </div>
                    <label class="col-sm-1 control-label">类型：</label>
                    <div class="col-md-4">
                		<d:select name="lendType" clazz="selectpicker" id="lendType" list="${lendTypes}" selected="${entity.lendType}"/>                                
                    </div>
            </div>
            
           	
			<div class="form-group">
				<label class="col-sm-1 control-label">时间：</label>
				<div class="col-md-6">
					<input type="text" class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'#F{$dp.$D(\'endAddTime\')}'})" id="beginAddTime" name="beginAddTime" value="${searchEntity.beginAddTime}" placeholder="开始时间" /> 至 
					<input type="text" class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', minDate:'#F{$dp.$D(\'beginAddTime\')}'})" id="endAddTime" name="endAddTime" value="${searchEntity.endAddTime}" placeholder="结束时间" />
					<button id="searchBtn" type="button" class="btn btn-sm btn-info"><i class="fa fa-search"></i> 查询</button>
					<a id="export_menu_btn" onclick = exportexcal() class="btn btn-sm btn-pink"><i class="fa fa-file-excel-o icon-share"></i> 导出</a>
				</div>
			</div>	
    </form>
    
    <form id= "exportexcalform" method=post action="${ctx}reportLend/export" target="_blank" >
					<input type="hidden" name="materialsName"  />
					<input type="hidden" name="code"  />
					<input type="hidden" name="orgName"  />
					<input type="hidden" name="lendType"  />
					<input type="hidden" name="beginAddTime"  />
					<input type="hidden" name="endAddTime"  />
	</form>
    
    <table id="table_data" class="table table-striped table-bordered table-hover">
        <thead>
        
        <tr>
            <th width="10%">单据号</th>
            <th width="10%">物资编号</th>
            <th width="10%">物资名称</th>
            <th width="9%">借还类型</th>
            <th width="8%">规格</th>
            <th width="8%">单位</th>
            <th width="8%">数量</th>
            <th width="12%">来往单位</th>
            <th width="10%">经办人</th>
            <th width="15%">借还时间</th>
           	<th width="6%">操作</th>
        </tr>
         
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var table = $("#table_data").dataTable({
            ajax: function(data, callback, settings){
                tableAjax($("#searchForm"),data, callback, settings);
            },
            //列表表头字段
            columns: [
                { "data": "code",name:"code",orderable:false },
                { "data": "materialsCode",name:"materials_code",orderable:false },
                { "data": "materialsName",name:"materials_name",orderable:false },
                { "data": "lendTypeStr",name:"lend_type", orderable:false },
                { "data": "specification",name:"specification",orderable:false },
                { "data": "unit",name:"unit",orderable:false },
                { "data": "num",name:"num",orderable:false },
                { "data": "orgName",name:"org_name",orderable:false },
                { "data": "agentName",name:"agent_name",orderable:false },
                { "data": "timeStr",name:"time",orderable:false },
                {
                    "data": "action",orderable:false,
                    "render": function ( data, type, row, meta ) {
                    	 var infoLend = "<a href='javacript:void(0);' onclick=\"handlerShow('" + row.id + "');\">查看</a>";
                    	 var infoReturn = "<a href='javacript:void(0);' onclick=\"handlerShowReturn('" + row.id + "');\">查看</a>";
                       if(row.lendType == 1){
                    	  return infoLend;
                       }  
                       if(row.lendType == 2){
                    	  return infoReturn;
                       } 
                        return "";
                    }
                }
        ]
    }).api();

        //查询条件
        $("#searchForm").submit(function(){
            table.ajax.reload();
            return false;
        });
    });
    
  //点击导出 将页面数据加载到表单中
	function exportexcal(){
		if($.trim($("#materialsName").val())=='' && $.trim($("#code").val())=='' && $.trim($("#orgName").val())=='' && $.trim($("#lendType").val())=='' && $.trim($("#beginAddTime").val())=='' && $.trim($("#endAddTime").val())=='' ){
			layer.msg("没有任何筛选条件，系统无法筛选结果，导出动作被取消！");
			return false;
		} 
		$('#exportexcalform input[name="materialsName"]').val($.trim($("#materialsName").val()));
		$('#exportexcalform input[name="code"]').val($.trim($("#code").val()));
		$('#exportexcalform input[name="orgName"]').val($.trim($("#orgName").val()));
		$('#exportexcalform input[name="lendType"]').val($.trim($("#lendType").val()));
		$('#exportexcalform input[name="beginAddTime"]').val($.trim($("#beginAddTime").val()));
		$('#exportexcalform input[name="endAddTime"]').val($.trim($("#endAddTime").val()));
		$('#exportexcalform').submit();
	}
    
	 // 物资出借查看
    function handlerShow(id){
    	var layerIndex = layer.open({
            title: "物资借还查看",
            type: 2,
            content: "/appMaterialsLend/record/"+ id,
            area: [$(window).width()+"px", $(window).height()+"px"]
        });
    }
	 // 物资归还查看
    function handlerShowReturn(id){
    	var layerIndex = layer.open({
            title: "物资归还查看",
            type: 2,
            content: "/appCheckPlan/info/"+id,
            area: ["60%", "90%"]
        });
    }
    
    
</script>
<!-- script end -->
</body>
</html>